<?php
/**
 * Created by PhpStorm.
 * User: xuzhong
 * Date: 2025/4/1
 * Time: 16:26
 */
namespace app\api\controller;
use think\Request;
use app\facade\Basic;
use  app\api\traits\ValidateTrait;
use think\exception\ValidateException;
class Article extends BaseController
{
    use ValidateTrait; // 使用 Trait
    ##员工信息
    protected $request;
    protected $service;
    protected $operator_id;
    protected $validationScenes  = [
        'index'=>[
            'pageIndex'=>['require|integer', 'staff.pageIndex'],
            'pageSize'  => [['require', 'between:1,100'], 'staff.pageSize'],
        ],
        'detail'=>[
            'id'=>['require', 'id'],

        ]

    ];

    public function __construct(Request $request)
    {
        $this->request = $request;
        $this->service = new \app\api\service\Article();

    }

    /**
     * @describe 获取文章列表
     * @author: xuzhong
     * @date: 2025-04-17 16:04:33
     * @param [] type
     * @return Renderable
     */
    public function index()
    {
        $params = $this->request->all();
        try {
            $this->autoValidate('index');
            // 验证通过逻辑...
        } catch (ValidateException $e) {
            // 错误处理...
            $customErrors = $e->getMessage()??'';
            return Basic::json(['code'=>100001, 'message'=>$customErrors ]);
        }


        $pageIndex  = isset($params['pageIndex'])   ? intval($params['pageIndex']) : 1;
        $pageSize   = isset($params['pageSize'])    ? intval($params['pageSize']) : 10;

        $res = $this->service->getList($params, $pageIndex, $pageSize);

        return Basic::json($res);
    }


    /**
     * @describe 文章详情
     * @author: xuzhong
     * @date: 2025-04-16 16:04:33
     * @param [] type
     * @return Renderable
     */
    public function detail(Request $request)
    {
        $params = $request->all();
        try {
            $this->autoValidate('detail');
            // 验证通过逻辑...
        } catch (ValidateException $e) {
            // 错误处理...
            $customErrors = $e->getMessage()??'';
            return Basic::json(['code'=>100001, 'message'=>$customErrors ]);
        }

        $res = $this->service->detail($params);

        return Basic::json($res);
    }

}